import Data.List
import Data.List
import Data.Array
import Data.Ord	

primes :: [Integer]
primes = 2 : filter ( (==1) . length . primeFactors ) [3,5..]

primeFactors :: Integer -> [Integer]
primeFactors n = factor n primes
	where
	factor n (p:ps)
		| p*p > n		 = [n]
		| n `mod` p == 0 = p : factor ( n `div` p )	(p:ps)
		| otherwise		 = factor n ps
		
truncationsr :: Integer -> [Integer]
truncationsr x
	| x < 10 = [x]
	| otherwise = x : truncationsr (x `div` 10)

truncationsl :: Integer -> [Integer]
truncationsl x
	| x < 10 = [x]
	| otherwise = x : truncationsl ( x `mod` 10^((floor.(/(log 10.0)).log.fromIntegral) x) )
	
isPrime :: Integer -> Bool
isPrime n
	| n <= 1 	= False
	| otherwise =((length(primeFactors n)) == 1)
	
euler_037 = sum $ take 11 $ filter (and.(map (isPrime)).truncationsr) $ filter (and.(map (isPrime)).truncationsl) [9..]